<template>
  <div>
    <div class="main">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>首页内容</span>
          <el-button v-if="userInfo.userType === '666'" style="float: right; padding: 3px 0" type="text" @click="isEdit = true">编辑</el-button>
        </div>
        <template v-if="isEdit">
          <wangEditor v-model="model.cValue" />
          <div style="margin-top: 10px;">
            <el-button type="primary" class="saveText" @click="seve">保存</el-button>
            <el-button class="cancelText" @click="cancelText">取消</el-button>
          </div>
        </template>
        <div v-else class="cValue" v-html="model.cValue" />
      </el-card>
    </div>
  </div>
</template>

<script>
import { postAction } from '@/api/manage'
import wangEditor from '@/components/xm/richText/wangEditor.vue'

export default {
  components: {
    wangEditor
  },
  mixins: [],
  props: {},
  data() {
    return {
      userInfo: this.$ls.get('USER_INFO') || {},
      isEdit: false,
      model: {}
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    console.log('网站开发者账号：QQ 463392823 微信同号搜索')
    this.get()
  },
  methods: {
    // 取消
    cancelText() {
      this.isEdit = false
      // this.model = Object.assign({}, this.originalModel) // 恢复初始数据
    },
    seve() {
      this.set()
    },
    // 获取配置
    get() {
      this.$store.dispatch('app/setLoading', true)
      postAction('generalConfigList.aspx?action=GetConfig', { cName: '首页内容' }).then((res) => {
        if (res.code === 1) {
          this.model = res.data || {}
          this.$message.success('获取首页信息成功')
        } else {
          this.$message.warning(res.message || '操作失败！')
        }
      }).finally(() => {
        this.$store.dispatch('app/setLoading', false)
      })
    },
    // 修改配置
    set() {
      this.$store.dispatch('app/setLoading', true)
      postAction('generalConfigList.aspx?action=Update', this.model).then((res) => {
        if (res.code === 1) {
          this.$message.success(res.message || '操作成功！')
        } else {
          this.$message.warning(res.message || '操作失败！')
        }
      }).finally(() => {
        this.isEdit = false
        this.$store.dispatch('app/setLoading', false)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}
.cValue{
  font-size: 18px;
}
</style>
